home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / pascal / gpc1.1p2 / gpc1 / usr / src / gpc-1.1p2-2.6.3 / GPC.GUIDE < prev    next >
Encoding:
Text File  |  1995-04-20  |  54.7 KB  |  1,832 lines

  1. Last modified: Sat Mar 25 21:09:05 1995
  2.  
  3. /* Copyright (C) 1993,1994 Free Software Foundation, Inc.
  4.  
  5. This file is part of GNU GCC.
  6.  
  7. GNU GCC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU GCC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU GCC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  20.  
  21.  
  22. Author: Juki <jtv@hut.fi>
  23. Gpc version 1.1 (2.6.3)
  24.  
  25.     
  26.         Notes On GNU Pascal (GPC)
  27.         =========================
  28.     
  29.     
  30. PURPOSE
  31. -------
  32.  
  33.     The purpose of the GNU Pascal project is to produce a
  34.     Pascal compiler (called GNU Pascal or gpc) which
  35.     - supports both the Pascal standard and the Extended Pascal
  36.       standard as defined by ISO and ANSI and IEEE.
  37.       (ISO 7185:1990, ISO/IEC 10206:1991, ANSI/IEEE770X3.160-1989)
  38.     - may be distributed under normal GNU license conditions
  39.     - can genarate code and run on any computer for which the GNU C
  40.       compiler can genarate code and run.
  41.  
  42.     One reason for this is the desire to promote the use of Extended
  43.     Pascal, which combines the clarity of Pascal with powerful
  44.     tools (e.g. modules and string manipulation) suitable for real-life
  45.     programming. Pascal was originally designed for teaching.
  46.     Extended Pascal provides a smooth way to proceed to challenging
  47.     programming tasks without learning a completely different language.
  48.  
  49.     GNU Pascal compiler is part of the GNU Compiler family
  50.     combining a language independent part of the GNU Compiler with
  51.     a Pascal specific front end.
  52.  
  53.     Other compilers of the family currently include compilers for
  54.     the C, C++ and Objective C languages.
  55.  
  56.  
  57. ABOUT THE PASCAL AND EXTENDED PASCAL LANGUAGES
  58. ----------------------------------------------
  59.  
  60.     Pascal is a well-known programming language and hardly needs to
  61.     be described here. Notice, however, that some people's idea of
  62.     Pascal is affected by acquaintance with such products as Turbo
  63.     Pascal which differ from the Pascal standard and provide a lot
  64.     of nonstandard extensions (some of which are compatible with
  65.     the Extended Pascal standard). Moreover, it is worth mentioning
  66.     that the ISO Pascal standard defines two levels of the language,
  67.     level 0 and level 1; the only difference between the levels is
  68.     that level 1 supports the so-called conformant array schemas
  69.     in parameter declarations.
  70.  
  71.     Extended Pascal is a standardized language which contains so
  72.     significant extensions to Pascal that it is best regarded as
  73.     a new language. It is currently not very well known, and computer
  74.     vendors do not seem to be eager to provide compilers for it.
  75.     Thus, there is social need for GNU Pascal supporting Extended
  76.     Pascal.
  77.  
  78.     Please refer to the document borland2ep.doc to find out more about
  79.     the differences between Turbo Pascal and Extended Pascal.
  80.     That document is written by Berend de Boer.
  81.  
  82.  
  83. STATUS
  84. ------
  85.  
  86.     The current version of GNU Pascal
  87.     - supports most of the Pascal standard
  88.     - supports a large subset of the Extended Pascal standard
  89.     - All input files are run through a preprosessor
  90.  
  91.     Conformant array schemas have been implemented, but they do not
  92.     work in all cases. Thus, GNU Pascal is at present basically
  93.     a level 0 compiler.
  94.  
  95.     GNU Pascal supports a large number of extensions to the Pascal
  96.     standard. They do not necessarily conform to the Extended Pascal
  97.     standard yet, but they will be checked and developed with the aim
  98.     of full conformance, plus some extensions to Extended Pascal.
  99.  
  100.     Unfortunately, the current version still contains deviations
  101.     from the Pascal standard, so GNU Pascal is not yet a valid
  102.     Pascal compiler, but not very far from it. The biggest
  103.     problems are:
  104.  
  105.       - Type checking is not as strict as required in the standard
  106.       - Run-time checks are not implemented.
  107.  
  108.     The rest of this document describes, in more detail, the
  109.     extensions to standard Pascal which are currently supported,
  110.     and some implementation decisions, features, and future plans.
  111.  
  112.  
  113. KNOWN DEFICIENCES:
  114. ------------------
  115.  
  116.     The biggest problem is that the GPC does not enforce the type
  117.     checking rules of Pascal. So it compiles programs that should
  118.     not be accepted because they violate the Pascal standard.
  119.     NOTE: If you can find these kind of problems in GPC, let me know.
  120.  
  121.     Run time checks are not implemented in the compiled code
  122.     (However, the GPC run time library traps most problems like it should).
  123.     This means that there is no compiler support for runtime checks
  124.     like array bounds checking, uninitialized variables, dereferencing
  125.     NIL and whatever.
  126.  
  127.     On a 64 bit machine (Alpha) some set operations do not work correctly
  128.     (I think the problem is in set union code).
  129.  
  130.     NEW and DISPOSE ignore variant selector fields.
  131.     (Gives warning, code works)
  132.  
  133.     Negative set bounds do not work.
  134.     
  135.     set of integer is currently limited to 4 words, that is on a 32
  136.     bit machine it is 0..255, on 64 bit machines it is 0..511
  137.     (Warning given.)
  138.  
  139.     Modules are only partially implemented...
  140.     
  141.     If your program declares lots of large variables you may run
  142.     out of stack (and get signal 11) because all program top-level
  143.     variables are also put in the stack. If you can't change the
  144.     stacklimit (e.g. with the "limit" command), put your variables
  145.     in a module; the top level vars there are not stored in stack.
  146.     Use modules to avoid this problem. But there is a risk of name
  147.     clashes on module top level declarations currently (a bug not
  148.     yet fixed).
  149.     
  150.     Functions returning strings don't work. (They are called
  151.     many times when the value is assigned; I'll fix this in the
  152.     next snapshot)
  153.  
  154.     Value parameter string type arguments has severe problems.
  155.     You should be able to pass one string as value parameter to
  156.     an undiscriminated string schema, and that should be the last
  157.     parameter. Otherwise, I suggest you currently pass them as var
  158.     parameters. To fix this requires a major rewrite.
  159.  
  160.     When compiling a 25000 line pascal program (The PAX
  161.     pascal compiler) with gpc it consumes *lots* of memory.
  162.     Gee, the gpc compiled Pax compiler compiled itself, but I
  163.     have not tested the resulting binary yet...
  164.  
  165. NOTE:
  166. -----
  167.     If I have to use constructs that affect the syntax of the language
  168.     I use tokens that look like __TOKEN__  (two adjacent underscores).
  169.     The current parser does not allow redefinition of these tokens,
  170.     but on the other hand, the extended pascal standard forbids
  171.     identifiers that start or end with an underscore. GCC also has
  172.     similar names for some extensions in C. (E.g. the word `Inline'
  173.     is no longer a "reserved" word; to compile routines inline,
  174.     use __inline__ instead.)
  175.  
  176.     The __cstring__ formal parameter type should convert a VALUE
  177.     string-type parameter (not a char_type) to a pointer and pass
  178.     that. If the actual parameter is a string schema, the address
  179.     of the character array is passed, not the address of the
  180.     schema object. Use with care.
  181.  
  182.     If a formal parameter is a pointer to a VOID type, e.g.
  183.  
  184.         type voidptr = ^void;
  185.  
  186.     any pointer value is accepted as the actual parameter.
  187.     Use with care, because it bypasses all type checking.
  188.  
  189.  
  190. PREPROSESSING FILES
  191. -------------------
  192.  
  193.     All GPC input files are now preprosessed automatically
  194.     before they are compiled.
  195.     
  196.     The preprosessor is a slightly modified version of the GNU C
  197.     preprosessor, and all features of the preprosessor are available
  198.     for the pascal programmer.
  199.  
  200.     These features include:
  201.  
  202.     - Include files with #include directive
  203.     - Conditional compilation with #if, #ifdef and so on
  204.     - Macros
  205.     - and more...
  206.  
  207.     For further information, please refer to the GNU CPP manual,
  208.     that is distributed with GNU C compiler. In a site that has
  209.     installed the GNU Emacs info files, you may view the manual
  210.     with the Emacs info command.
  211.     
  212.     If you wish to see what happens to the source file when the
  213.     preprocessor is done with it, use the '-E' flag with the gpc
  214.     command.
  215.     
  216.  
  217. EXTENSIONS TO ISO-7185 PASCAL LANGUAGE:
  218. ---------------------------------------    
  219.  
  220.     GPC contains a number of extensions to the ISO 7185 Pascal language.
  221.  
  222.     Most of these extensions are written so that they should conform
  223.     conform to the international standard ISO/IEC 10206 : 1991, Information
  224.     technology - Programming Languages - Extended Pascal.
  225.     
  226.     GPC is not yet fully compliant to the requirements of the Extended
  227.     Pascal language.
  228.  
  229.     The following Extended Pascal features are implemented:
  230.     - I/O from/to strings
  231.     - append file open mode: extend(File)
  232.     - binding of external objects (GPC supports only binding of files)
  233.     - complex dyadic operations +,-,/,* and monadic -,+
  234.     - complex exponentiation operators (POW and **)
  235.     - complex functions (sqr,arctan,sqrt,exp,ln,sin,cos)
  236.     - complex number info with re, im and arg functions
  237.     - complex numbers constructed by cmplx or polar
  238.     - constant expressions
  239.     - direct access I/O
  240.     - exponentiation operators (POW and **)
  241.     - function result variable
  242.     - functions returning structured types
  243.     - generalized Succ/Pred (val := succ (val, 5);)
  244.     - gettimestamp, date, time
  245.     - halt procedure
  246.     - initial values to type declarations and/or variable declarations
  247.     - local variable declarations may dynamically select the type and size
  248.     - maxchar/minreal/maxreal/epsreal values.
  249.     - modules are partially supported (@@@incomplete, see below)
  250.     - non-decimal numbers, base from 2 through 36: base#number
  251.     - pointer and component access of structured return values 
  252.     - protected parameters
  253.     - ranges and otherwise in case statements and variant records
  254.     - read procedure can read strings from text files
  255.     - relaxation of rules on number & order of declarations
  256.     - required module interfaces StandardInput and StandardOutput
  257.     - restricted types
  258.     - set extensions (symmetric difference(XOR) and CARD)
  259.     - short circuit logical operators (AND_THEN, OR_ELSE)
  260.     - standard numeric input (ISO 6093)
  261.     - string and char values are compatible
  262.     - string catenations with "+"
  263.     - string comparisons with and without padding
  264.     - string functions (trim,substr,index,length)
  265.     - string schema (variable length strings)
  266.     - string schema discriminant 'Capacity' dynamically set with NEW
  267.     - substring variables (str[5..7] := 'foo';)
  268.     - type inquiry
  269.     - underscore in identifiers
  270.     - zero fieldwidth output
  271.     
  272.     Gpc extensions not in Extended Pascal:
  273.     - alphanumeric labels
  274.     - assembler code inclusion with access to variables
  275.     - character escapes in strings
  276.     - close file (@@@ unbind(F) also closes a bound file F)
  277.     - computed goto
  278.     - function pointers
  279.     - halt procedure may have a numeric exit status parameter
  280.     - mark/release
  281.     - optional file name in reset/rewrite/extend as a string
  282.     - return / break / continue statements
  283.     - simple "modules" in addition to the Extended Pascal modules.
  284.     - sizeof/alignof functions
  285.     - string[ XX ] works like string(XX) as a string schema type selector
  286.     - storage qualifiers in variable declarations
  287.     - synonyms for otherwise: others and default
  288.     - taking address of labels
  289.     - taking address of objects
  290.     - type casts
  291.     - type qualifiers
  292.     - module initializers can be run in user specified order
  293.     - source file preprosessor
  294.     
  295.  
  296. EXTENDED PASCAL FEATURES STILL MISSING FROM GPC:
  297. ------------------------------------------------
  298.     
  299.     - set member iteration (FOR ch IN [ 'a'..'z','0'..'9' ] DO...)
  300.     - set types with variable bounds
  301.     - structured value constructors
  302.     - general schema types & make NEW work with them
  303.     - some features of the module interface missing
  304.     - subrange lower bound as an expression
  305.       (this is *hard* to do with an LALR(1) parser in single pass!
  306.        GPC allows upper bound as an arbitrary expression;
  307.        lower bound must now be an identifier, a constant or a
  308.        variable name.)
  309.         
  310.     
  311. I/O TO TEXT FILES:
  312. ------------------
  313.  
  314.     GPC implements "lazy" text file I/O, i.e. do a PUT as soon
  315.     as you can and do GET as late as you can.
  316.  
  317.     This should avoid most of the problems sometimes considered
  318.     to be the most stupid feature of Pascal.
  319.  
  320.     When passing a file buffer as parameter the buffer
  321.     is validated when the parameter is passed.
  322.     @@@ Perhaps it would be nice to hack it to be validated when
  323.     the VAR parameter is referenced...
  324.  
  325.     When any lazy file is RESET, the file buffer state is set
  326.     to undefined. It is validated on the first reference to it.
  327.     Now this is also true for terminal devices.
  328.  
  329.     
  330. VARIABLE LENGTH STRINGS IN GPC:
  331. -------------------------------    
  332.     
  333.     Extended Pascal has a "type selector" feature called schema
  334.     types.
  335.  
  336.     GPC does not yet implement general schema types, but the STRING
  337.     SCHEMA is now implemented.
  338.  
  339.     (An example of a (unimplemented) schemata would be, e.g:
  340.  
  341.      Matrix (N,M: Positive_int) = array [ 1..N, 1..M ] of integer;
  342.          
  343.     Here the M and N are discriminant identifiers.)
  344.  
  345.     A STRING SCHEMA is the only predefined schema type in Extended
  346.     Pascal, with one required discriminant identifier "Capacity".
  347.  
  348.     The string schema type, if explicitely defined, could look like:
  349.     TYPE string(capacity) = packed array [ 1..capacity ] of char;
  350.  
  351.     Internally GPC implements STRING SCHEMA as follows:
  352.  
  353.     The type representing the SCHEMA TYPE is a RECORD_TYPE node,
  354.     with the following fields:
  355.  
  356.     STRING  = RECORD
  357.             Capacity : integer;
  358.             length   : integer;
  359.             string   : packed array [ 1..Capacity ] of char;
  360.           END;
  361.  
  362.     The "Capacity" field may be directly referenced by user,
  363.  
  364.     "length" is referenced by a predefined string function
  365.     LENGTH(str) and contains the current string length.
  366.  
  367.     "string" contains the chars in the string.
  368.  
  369.     The "string" and "length" fields can not be directly referenced
  370.     by a user program.
  371.  
  372.     References to the schema discriminants are allowed, and
  373.     the WITH statement is also allowed, so one can say:
  374.  
  375.      var str : string (80);
  376.      begin
  377.         writeln (str.capacity), (* writes 80 *)
  378.     
  379.         with str do
  380.           writeln (capacity);   (* writes 80 *)
  381.      end;
  382.     
  383.     When a new SCHEMA_TYPE is created, the discriminant identifier
  384.     fields need to be initialized. GPC initializes the new schema
  385.     type discriminant identifiers of every VAR_DECL node before it
  386.     executes any instructions of the procedure, function or
  387.     program where the string variable is declared.
  388.  
  389.     If new internal schema types are created (for conversion
  390.     of fixed-string or char type parameters to a string schema
  391.     formal parameter), the discriminant identifiers are
  392.     initialized immediately. The discriminant identifiers
  393.     of PARM_DECL nodes are not initialized separately, they
  394.     get their values from the actual parameters.
  395.  
  396.     If a parameter is a SCHEMA_NAME (a schema with no discriminant
  397.     identifiers), a proto string schema is used as the type
  398.     of the parameter.
  399.  
  400.     VAR-parameter:
  401.     An actual parameter to a formal schema name must be of
  402.     STRING_SCHEMA type. The type of the actual parameter is used
  403.     instead of the proto schema for the formal parameter.
  404.     
  405.     VALUE-parameter:
  406.     An actual parameter to a schema name may be either a
  407.     STRING_SCHEMA type, a fixed string type or a char type.  If
  408.     the actual parameter is a string schema type, that is used
  409.     instead of the proto schema. If it is not a schema, a new
  410.     variable length string VAR_DECL is created, the actual
  411.     parameter is copied to the new variable and the "capacity"
  412.     field is set to the length of the actual variable.
  413.     
  414.     Variable length string parameters look like:
  415.  
  416. PROGRAM Zap (output);
  417.  
  418. TYPE
  419.    stype = string (10);
  420.    sptr  = ^string;
  421.  
  422. VAR
  423.    str  : stype;
  424.    str2 : string(100000);
  425.    dstr : ^string;
  426.    zstr : sptr;
  427.    len  : integer value 256;
  428.  
  429.   (* "string" accepts any length of strings *)
  430.   PROCEDURE foo(z: string);
  431.  
  432.   BEGIN
  433.     writeln ('Capacity : ',z.capacity);
  434.     writeln ('Length   : ',length (z));
  435.     writeln ('Contents : ',z);
  436.   END;
  437.  
  438.   (* Another way to use dynamic strings *)
  439.   PROCEDURE bar(slen : integer);
  440.  
  441.   var
  442.     lstring : string (slen);
  443.     foostr  : type of lstring;
  444.  
  445.   BEGIN
  446.     lstring := 'Hello World!';
  447.     foo (lstring);
  448.     foostr := 'Ent{ miksi juuri t{m{?';
  449.     foo(foostr);
  450.   END;
  451.  
  452. BEGIN
  453.   str   := 'KUKKUU';
  454.   str2  := 'A longer string variable';
  455.     
  456.   new (dstr, 1000);    { Select the string Capacity with NEW }
  457.   dstr^ := 'The max length of this is 1000 chars';
  458.   new (zstr, len);
  459.   zstr^ := 'This should fit here';
  460.     
  461.   foo(str);
  462.   foo(str2);
  463.   foo('This is a constant string');
  464.   foo('R');        { A char parameter to string routine }
  465.   foo('');        { An empty string }
  466.   foo (dstr^);
  467.   foo (zstr^);
  468.   bar (10000);
  469. END. (* Zap *)
  470.         
  471.     In the above example, the required procedure NEW was used
  472.     to select the capacity of the strings. Procedure "BAR" also has
  473.     a string whose size depends of the parameter passed to it
  474.     and another string whose type will be the same than the type of
  475.     the first string ("type of" construct).
  476.  
  477.     All string and char types are compatible as long as the
  478.     destination string is long enough to hold the source in
  479.     assignments. If the source string is shorter than the
  480.     destination, the destination is automatically blank padded if
  481.     the destination string is not of string schema type.
  482.  
  483.  
  484. STRING ROUTINES (mostly in library):
  485. ------------------------------------
  486.  
  487.     S1 and S2 may be of string or char type.
  488.     S is of string type.
  489.  
  490.     WRITESTR (s, write-parameter-list)
  491.     READSTR (s, read-parameter-list)
  492.  
  493.         Write to a string and read from a string.
  494.         The parameter lists are identical to write/read from TEXT
  495.         files. The semantics is closely modeled after
  496.         file I/O.
  497.  
  498.     INDEX(s1,s2)
  499.  
  500.         If S2 is empty, return 1 else if S1 is empty return 0
  501.         else returns the position of s2 in s1 (an integer).
  502.  
  503.     LENGTH (s1)
  504.  
  505.         Return the length of S1 (an integer from 0..Capacity)
  506.  
  507.     TRIM (s1)
  508.  
  509.         Returns a new string with spaces stripped of the end of S.
  510.  
  511.     SUBSTR (s1, i)
  512.     SUBSTR (s1, i, j)
  513.  
  514.         If J is missing it is calculated as: J := LENGTH (S1) - I + 1;
  515.         Return a new substring of S1 that contains J characters
  516.         starting from I.
  517.  
  518.     EQ (s1,s2)
  519.     NE (s1,s2)
  520.     LT (s1,s2)
  521.     LE (s1,s2)
  522.     GT (s1,s2)
  523.     GE (s1,s2)
  524.  
  525.         Lexicographic comparisons of S1 and S2. Returns boolean result.
  526.         Strings are not padded with spaces.
  527.  
  528.     s1  = s2
  529.     s1 <> s2
  530.     s1  < s2
  531.     s1 <= s2
  532.     s1  > s2
  533.     s1 >= s2
  534.  
  535.         Pascal string compare of S1 and S2. Returns boolean result.
  536.         Shorter string is blank padded to length of the longer one.
  537.     
  538.  
  539. NO NAME SPACE POLLUTION WITH EXTENSIONS:    
  540. ----------------------------------------    
  541.  
  542.     In GPC you are free to re-define everything that is not a
  543.     reserved word in ISO 7185 Pascal in your program.
  544.  
  545.     All Extended Pascal additional "reserved words" may be redefined,
  546.     so you do not have to modify your code for GPC if you have an
  547.     identifier like RESTRICTED or VALUE or some such.
  548.     @@ This violates Extended Pascal standard.
  549.  
  550.     You may also redefine words like INTEGER and CHAR if you like.
  551.  
  552.     @@@@ NOTE: The *only* exception to the redefinition rule currently
  553.     is the word INLINE (to make routines inline compiled), because I
  554.     added it in front of PROCEDURE or FUNCTION.  But I think I will
  555.     change the syntax later and make INLINE a directive instead of a
  556.     reserved word.
  557.  
  558.  
  559. COMPILE TIME SWITCHES:
  560. ----------------------    
  561.  
  562.     to get info of possible clashes of keywords and other
  563.     info of your program constructs that gpc thinks are "non-standard"
  564.     use the switch "-pedantic" when compiling. See the GCC info files.
  565.     
  566.     @@@ I have not tested the switches like -Wall very much. If you do,
  567.     @@@ give me info of error messages that don't make sense in Pascal.
  568.  
  569.     @@@ As a rule, GPC implements most of the switches GCC implements,
  570.     and a couple of more that can not currently be set.
  571.     
  572.  
  573. IMPLEMENTED DIRECTIVES:
  574. -----------------------
  575.  
  576.     FORWARD        Required by pascal standard.
  577.     
  578.     EXTERNAL    External routine which starts with a capital letter.
  579.             (e.g. calling external function "foo()" will
  580.              actually call "Foo()")
  581.     EXTERN        Same as external
  582.  
  583.     C        Calls external routine "foo()" as "foo()"
  584.             (no capitalization of the first letter)
  585.     C_LANGUAGE    Same as C.
  586.     
  587.     STATIC        Make a function static in C sense.
  588.     
  589.  
  590.  PROGRAM foo;
  591.     
  592.  PROCEDURE gotoxy(x,y: Integer); C;
  593.     
  594.  BEGIN
  595.    gotoxy(10,10); (* Call external routine "gotoxy" *)
  596.  END.
  597.     
  598.  
  599. SET OPERATIONS:
  600. ---------------
  601.  
  602.     GPC supports standard Pascal set operations. In addition it
  603.     supports the extended Pascal set operation symmetric
  604.     difference (set1 >< set2) operation (a XOR of the set
  605.     elements).
  606.  
  607.     It also has a function that counts the elements in the set:
  608.     a := card (set1)
  609.  
  610.     NOTE:
  611.     the set operations are still under construction, e.g. the set
  612.     code does not fully work in the 64 bit Alpha machines.
  613.  
  614.  
  615. INITIAL VALUES TO TYPE DENOTERS:
  616. --------------------------------
  617.  
  618.     A type (or variable) may be initialized to a value of
  619.     expression when it is declared, as in:
  620.  
  621. program zap;
  622.  
  623. type
  624.    int10   = integer value 10;
  625.    footype = real;
  626.    mytype  = char value pred('A');
  627.    etype   = (a,b,c,d,e,f,g) value d;
  628.  
  629. var
  630.    ii  : int10;        (* Value of ii set to 10 *)
  631.    ch  : mytype  value pred('z');
  632.    aa  : integer value ii+10;
  633.    foo : footype value sqrt(aa);
  634.    e1  : etype;        (* value set to d *)
  635.    e2  : etype value g; (* value set to g *)
  636.  
  637. begin
  638. end.
  639.  
  640.     Extended pascal requires the type initializers to be
  641.     constant expressions. GPC allows any valid expression.
  642.     
  643.     Note, however, that the expressions that affect the size
  644.     of storage allocated for objects (e.g. the length of
  645.     arrays) may contain variables only inside functions or
  646.     procedures.
  647.  
  648.     GPC evaluates the initial values used for the type
  649.     when an identifier is declared for that type.
  650.     If a variable is declared with a type-denoter that
  651.     uses a type-name which already has an initial value
  652.     the latter initialization has precedence.
  653.     
  654.     @@@@ GPC does not know how to calculate constant
  655.     values for math functions in the runtime library
  656.     at compile time, e.g. exp(sin(2.4567)), so you should
  657.     not use these kind of expressions in object size
  658.     expressions. (Extended Pascal allows this).
  659.  
  660.  
  661. DATE AND TIME ROUTINES:
  662. -----------------------
  663.  
  664.     Predefined date and time routines:
  665.      procedure gettimestamp(VAR t: Timestamp);
  666.      function date(t: Timestamp) : packed array [ 1..DATE_LENGTH ] of char;
  667.      function time(t: Timestamp) : packed array [ 1..TIME_LENGTH ] of char;
  668.         
  669.     DATE_LENGTH and TIME_LENGTH are implementation dependent constants.
  670.     See E.20 and E.22 in chapter IMPLEMENTATION DEPENDENT FEATURES
  671.     to find out these values for GPC.
  672.  
  673.     GetTimeStamp(t) fills the record T with values. If they are
  674.     valid, the boolean flags are set to TRUE.
  675.  
  676.     TimeStamp is a required predefined type in extended pascal standard.
  677.     (It may be extended in an implementation.)
  678.  
  679.     The required part of the type looks like:
  680.  
  681.     TimeStamp = PACKED RECORD
  682.                  DateValid,
  683.                  TimeValid : Boolean;
  684.                  year      : integer;
  685.                  month     : 1 .. 12;
  686.                  day       : 1 .. 31;
  687.                  hour      : 0 .. 23;
  688.                  minute    : 0 .. 59;
  689.                  second    : 0 .. 59;
  690.                    END;
  691.  
  692.     @@@ NOTE:
  693.     TimeStamp may be later extended in GPC to contain the
  694.     following fields at the end of the TimeStamp record:
  695.  
  696.            Dst_used   : Boolean; (* If daylight savings are used *)
  697.            TimeZone   : Integer; (* Positive if WEST, in minutes *)
  698.            Weekday    : 0..6;    (* 0 is Sunday *)
  699.            TimerValid : Boolean; (* Is the following timer valid *)
  700.            us_Timer   : Integer; (* A microsecond timer that is a 32 bit
  701.                     modulus of the timer returned by the
  702.                     system. *)
  703.  
  704.     Fields Dst_used, TimeZone and WeekDay will be valid when DateValid
  705.     is TRUE. Field us_Timer will be valid when TimerValid is TRUE.
  706.  
  707.  
  708. COMPLEX TYPE AND OPERATIONS:
  709. ----------------------------
  710.  
  711.     The following sample programs illustrates most of the
  712.     COMPLEX type operations. In addition monadic + and - are
  713.     supported and dyadic +,-,*,/ operations.
  714.  
  715. program complex_test(output);
  716.  
  717. var
  718.    z1,z2       : complex;
  719.    len, angle  : real;
  720.  
  721. begin
  722.    z1 := cmplx (2,1);
  723.    writeln;
  724.    writeln ('Complex number Z1 is: (',re(z1):1,',',im(z1):1,')');
  725.    writeln;
  726.    z2 := conjugate(z1); { GPC extension }
  727.    writeln ('Conjugate of Z1 is: (',re(z2):1,',',im(z2):1,')');
  728.    writeln;
  729.    len   := abs (z1);
  730.    angle := arg (z1);
  731.    writeln ('The polar representation of Z1 is LENGTH=',len:1,
  732.         ' ANGLE=',angle:1);
  733.    writeln;
  734.    z2    := polar (len, angle);
  735.    writeln ('Converting (LENGTH,ANGLE) back to (X,Y) gives: (',
  736.         re(z2):1,',',im(z2):1,')');
  737.    writeln;
  738.    writeln ('The following operations operate on the complex number Z1');
  739.    writeln;
  740.  
  741.    z2 := arctan (z1);
  742.    writeln ('arctan:  R=',re(z2),', I=',im(z2));
  743.    z2 := z1 ** 3.141;
  744.    writeln ('**3.141: R=',re(z2),', I=',im(z2));
  745.    { cos, ln, exp, sqrt and sqr exist also }
  746.    z2 := sin(z1);
  747.    writeln ('sin:     R=',re(z2),', I=',im(z2));
  748.    z2 := z1 pow 8;
  749.    writeln ('POW 8:   R=',re(z2),', I=',im(z2));
  750.    z2 := z1 pow (-8);
  751.    writeln ('POW (-8):  R=',re(z2),', I=',im(z2));
  752. end.
  753.     
  754.  
  755. DIRECT ACCESS FILES:
  756. --------------------
  757.  
  758.     @@@@ Not tested.
  759.     @@@@ Write a demo program.
  760.  
  761.     type
  762.            Dfile = file [ 1 .. 100 ] of integer;
  763.     var
  764.        F : Dfile;
  765.        P, N : 1..100;
  766.        
  767.     Declares a type for a file that contains 100 integers.
  768.     
  769.     The following direct access routines may be applied to a
  770.     direct access file:
  771.  
  772.     SeekRead   (F, N);    { Open file in Inspection mode, seek to record N }
  773.     SeekWrite  (F, N);    { Open file in Generation mode, seek to record N }
  774.     SeekUpdate (F, N);    { Open file in Update mode, seek to record N }
  775.     Update (F);        { Writes F^, position not changed. F^ kept. }
  776.     p := Position (F);    { Return current record number }
  777.     p := LastPosition (F);    { Return the last record number in file }
  778.     
  779.     If the file is open for Inspection or Update, GET may be applied.
  780.     If the file is open for Generation or Update, PUT may be applied.
  781.  
  782.     @@@ GPC acts like the file would always start at record number 0,
  783.     and subtracts/adds the lower index from the record number.
  784.     If you think this is incorrect, let me know.
  785.     
  786.  
  787. RESTRICTED TYPES:
  788. -----------------
  789.  
  790.     Extended Pascal defines restricted types as:
  791.  
  792.       restricted-type = 'restricted' type-name .
  793.  
  794.     A value of a restricted type may be passed as a value parameter
  795.     to a formal parameter possessing its underlying type, or returned
  796.     as the result of a function. A variable of a restricted type may
  797.     be passed as a variable parameter to a formal parameter possessing
  798.     the same type or its underlying type. No other operations, such as
  799.     accessing a component of a restricted type value or performing
  800.     arithmetic, are possible.
  801.     
  802. program zap;
  803.  
  804. type
  805.    unres_rec =  record
  806.           a :  integer;
  807.         end;
  808.  
  809.    res =  restricted unres_rec;
  810.  
  811. var
  812.    r1 :  unres_rec;
  813.    r2 :  res;
  814.  
  815.    i  :  restricted integer;       
  816.    k  :  integer;       
  817.  
  818.   function zap(p : unres_rec) : res;
  819.   var
  820.      ures :  unres_rec;
  821.  
  822.   begin
  823.      { The parameter is treated as unrestricted, even though the actual
  824.        parameter may be a restricted object }
  825.      ures.a := p.a;
  826.  
  827.      { Legal to assign a return value }
  828.      zap := ures;
  829.   end; { zap }
  830.  
  831. begin
  832.    r1.a := 354;
  833.     
  834.    { Assigning a restricted return value to a restricted object }
  835.    { @@@ Verify if this should really be allowed????? }
  836.    r2 := zap(r1);
  837.     
  838.    { Passing a restricted object to unrestericted formal parameter is ok }
  839.    r2 := zap(r2);
  840.  
  841.    { *** The following are illegal *** }
  842.    r2.a := 100;      { field access }
  843.    r1 := r2;      { := source is restricted type }
  844.    r2 := r1;      { := target is restricted type }
  845.    r1 := zap(r2); { := a restricted return value to unrestricted object }
  846.    i  := 16#ffff; { := target is restricted type }
  847.    k  := i + 2;   { Arithmetic with restricted type }
  848. end.
  849.     
  850.     
  851. EXTENDED PASCAL MODULES:
  852. ------------------------
  853.  
  854.     @@@ Gpc does not yet support:
  855.       - renaming with '=>'
  856.       - QUALIFIED interfaces
  857.       - PROTECTED export variables
  858.       - ONLY
  859.       - IMPORT does not work semantically correct.
  860.       - EXPORT does not work semantically correct.
  861.       - exported ranges (compiler calls abort())
  862.       - module parameter lists    
  863.  
  864.     Gpc should be able to parse full Extended Pascal module syntax.
  865.     But all the features are not implemented yet.
  866.  
  867.     You may load one PROGRAM and several MODULEs to make up
  868.     one pascal program. A single file may contain zero or more
  869.     modules and/or zero or one programs.
  870.     
  871.     Please NOTE:
  872.     If you have many modules in the same file, the variable
  873.     and function declarations are visible after the point they
  874.     have been declared in the implementation even if the interface
  875.     does not export them. But they do not become visible only
  876.     by including the interface to another file and separate
  877.     compiling that (so you do need to export them now).
  878.     (@@@ unfortunately, currently this applies only to variables
  879.      and functions; all other things are visible after the interface
  880.      has been compiled whether or not you exported them.)
  881.  
  882.     The nicest way to handle the module interface in separate
  883.     compilation environment is to use the non-standard
  884.  
  885.         #include "module-interface.ph"
  886.  
  887.     feature. You can collect your module interfaces to a single
  888.     directory and include them from there by using the
  889.     "-I DIR" switches to specify the include file search paths
  890.     to the compiler. (See the GNU CPP manual for more info).
  891.  
  892.     There is currently no attempt to avoid name clashes
  893.     of separate compiled modules when they are linked together.
  894.     (The exported variables and functions having the same name
  895.      in different modules will clash!!!)
  896.  
  897.     Sample module code with separate INTERFACE and IMPLEMENTATION
  898.     parts follows:
  899.  
  900. MODULE foobar Interface;    (* INTERFACE *)
  901.     
  902.   EXPORT catch22 = (footype,setfoo,getfoo);
  903.  
  904.   TYPE footype = integer;
  905.  
  906.   PROCEDURE setfoo(f: footype);
  907.   FUNCTION  getfoo: footype;
  908.  
  909. END. { module foobar interface }
  910.  
  911.     
  912. MODULE foobar Implementation;    (* IMPLEMENTATION *)
  913.  
  914.   IMPORT StandardInput;
  915.      StandardOutput;
  916.  
  917.   VAR foo : footype;
  918.  
  919.   { Note: the effect is the same as the Forward directive would have:
  920.     parameter lists and return types are not "allowed" in the declaration
  921.     of exported routines.
  922.   }
  923.   PROCEDURE setfoo;
  924.   BEGIN
  925.     foo := f;
  926.   END;
  927.  
  928.   FUNCTION getfoo;
  929.   BEGIN
  930.     getfoo := foo;
  931.   END;
  932.  
  933.   TO BEGIN DO
  934.     BEGIN
  935.       foo := 59;
  936.       writeln ('Just an example of a module initializer. See comment below');
  937.     END;
  938.  
  939.   TO END DO
  940.    BEGIN
  941.      foo := 0;
  942.      writeln ('Goodbye');
  943.    END;
  944.     
  945. END. { foobar implementation }
  946.  
  947.     
  948.     Alternatively the module interface and implementation may
  949.     be combined as follows:
  950.     
  951.     
  952. MODULE foobar;            (* ALTERNATIVE METHOD *)
  953.     
  954.   EXPORT catch22 = (footype,setfoo,getfoo);
  955.  
  956.   TYPE footype = integer;
  957.  
  958.   PROCEDURE setfoo(f: footype);
  959.   FUNCTION getfoo: footype;
  960.  
  961.   END; { NOTE: this END is required here, even if the
  962.      module-block below would be empty. }
  963.  
  964.   VAR foo : footype;
  965.  
  966.   PROCEDURE setfoo;
  967.   BEGIN
  968.     foo := f;
  969.   END;
  970.  
  971.   FUNCTION getfoo;
  972.   BEGIN
  973.     getfoo := foo;
  974.   END;
  975.  
  976. END. { module foobar }
  977.     
  978.     Either one of the two methods may be used with:
  979.  
  980. PROGRAM what(output);
  981.  
  982. import catch22;
  983.     
  984. BEGIN
  985.   setfoo (999);
  986.   writeln (getfoo);
  987. END.
  988.  
  989.     The INTERFACE has to be in the same file as the program/module that
  990.     uses it's exported names.  Otherwise GPC does not know anything
  991.     about it and fails to compile the file.
  992.  
  993.     @@@ What is the portable way to avoid this? It could be done
  994.     @@@ with the #include "interface.p" but that is not portable.
  995.     @@@ Neither is deriving the file name from the interface name.
  996.     @@@ Suggestions, please. Portable suggestions preferred :-)
  997.     @@@
  998.     @@@ How about making the compiler front end read some user
  999.     @@@ defined compiling-environment description file that
  1000.     @@@ binds the imported names to some machine specific files
  1001.     @@@ and pass the info to the compiler? This way the source
  1002.     @@@ does not need to have any knowledge of the extenal binding.
  1003.     
  1004.     
  1005. SOMEWHAT SIMPLER GPC MODULES ARE ALSO SUPPORTED:
  1006. ------------------------------------------------
  1007.     
  1008.     Note: this is not supported in Extended Pascal standard.
  1009.  
  1010.     This is a simpler module support that does not
  1011.     require exports, imports, module headers etc.
  1012.     
  1013.     These non-standard simple Gpc modules look like
  1014.     (does not have an export part, does not have a separate
  1015.      module-block, does not use import/export features.)
  1016.  
  1017. MODULE foobar;
  1018.   TYPE footype = integer;
  1019.   VAR foo: footype;
  1020.  
  1021.   PROCEDURE setfoo(f: footype);
  1022.   BEGIN
  1023.     foo := f;
  1024.   END;
  1025.  
  1026.   FUNCTION getfoo: footype;
  1027.   BEGIN
  1028.     getfoo := foo;
  1029.   END;
  1030. END.
  1031.  
  1032.  
  1033. PROGRAM what(output);
  1034.  
  1035.   (* In case the module foobar is loaded from another file *)
  1036.   PROCEDURE setfoo(f: footype); External;
  1037.   FUNCTION  getfoo: footype;    External;
  1038.  
  1039. BEGIN
  1040.   setfoo (999);
  1041.   writeln (getfoo);
  1042. END.
  1043.  
  1044.     
  1045. MODULE INITIALIZATION AND FINALIZATION:
  1046. ---------------------------------------    
  1047.     
  1048.  
  1049.     TO BEGIN DO module initialization and TO END DO module finalization
  1050.     constructs are supported if the GNU compiler supports constructors
  1051.     and destructors in your target machine. (It always does if you
  1052.     use the GNU Linker).
  1053.  
  1054.     If the initialization and finalizations do not work by default, but
  1055.     you have the GNU Linker, use option -fgnu-linker when compiling the
  1056.     program.
  1057.  
  1058.     I re-implemeted the standard I/O handling and now the input and
  1059.     output can also be used from the initialization and finalization
  1060.     parts.
  1061.  
  1062.     @@@ Try these, send me bug reports. These are not tested.
  1063.     
  1064.  
  1065. BINDING OF OBJECTS TO EXTERNAL NAMES:
  1066. -------------------------------------
  1067.  
  1068.     GPC supports the extended pascal bind,unbind and binding
  1069.     operations when applied to files.
  1070.  
  1071.     The compiler will currently reject binding of other object
  1072.     types (@@@ Perhaps the run time system should do the rejection?)
  1073.  
  1074.     GPC implements extensions to the required predefined record type
  1075.     BindingType:
  1076.  
  1077.     BindingType = PACKED_RECORD
  1078.             Bound           : Boolean;
  1079.             Extensions_Valid  : Boolean;
  1080.             Writable      : Boolean;
  1081.             Readable          : Boolean;
  1082.             Existing      : Boolean;
  1083.             Error          : Integer; { Unused currently }
  1084.             Size          : Integer; { # of elements or -1 }
  1085.             Name          : String (BINDING_NAME_LENGTH);
  1086.               END;
  1087.  
  1088.     The fields BOUND and NAME are required by the standard. All other
  1089.     fields are extensions.
  1090.  
  1091.     The meaning of the extensions to the BindingType record type,
  1092.     and the value of BINDING_NAME_LENGTH is defined in this document,
  1093.     section IMPLEMENTATION DEFINED FEATURES (E.14). It is a compiler
  1094.     constant, the run time system accepts any length.
  1095.  
  1096.     The Size field is a latest addition to BindingType; I added that because
  1097.     the direct access files actually require that the file is not bigger
  1098.     that the definition; and lastposition(file) does not work before the
  1099.     file is opened. The "Size" field can then be used to determine
  1100.     the size before open, and if the upper bound of the direct access
  1101.     file is a variable one should be able to open files of any size
  1102.     without violating the standard.
  1103.  
  1104.     The following is an example of the binding:
  1105.  
  1106.  
  1107. program z(input,output,f);
  1108.  
  1109. var
  1110.    f :  text;
  1111.    
  1112. procedure bindfile (var    f :  text);
  1113. var
  1114.    b : BindingType;
  1115.  
  1116. begin
  1117.   unbind (f);
  1118.   b := binding (f);
  1119.   repeat
  1120.     write ('Enter file name:');
  1121.     readln (b.name);
  1122.     bind (f, b);
  1123.     b := binding (f);
  1124.     if not b.bound then
  1125.       writeln ('File not bound--try again');
  1126.   until b.bound;
  1127. end;
  1128.  
  1129. begin
  1130.  
  1131.   bindfile (f);
  1132.  
  1133.   (* Now the file F is bound to an external file.
  1134.    *
  1135.    * You can use the implementation defined fields
  1136.    * to check if the file is Readable, Writable and
  1137.    * if it Exists. These are valid if the.Extensions_Valid
  1138.    * field is TRUE.
  1139.    *)   
  1140. end.
  1141.  
  1142. FUNCTION POINTERS:
  1143. ------------------
  1144.  
  1145.     GPC suports also function pointers and calls through them.
  1146.     This is a non-standard feature.
  1147.  
  1148. program zap(output);
  1149.  
  1150. type
  1151.     proc_ptr = ^ procedure (integer);
  1152.  
  1153. var
  1154.     pvar : proc_ptr;
  1155.  
  1156. procedure write_int(i: integer);
  1157. begin
  1158.   writeln ('Integer: ',i:1);
  1159. end;
  1160.  
  1161. begin
  1162.   (* PVAR points to function WRITE_IT *)
  1163.   pvar := &write_int;
  1164.     
  1165.   (* Dereferencing a function pointer calls the function *)
  1166.   pvar^(12345);
  1167. end.
  1168.  
  1169.  
  1170. STRING CATENATION:
  1171. ------------------
  1172.  
  1173.     Gpc supports string catenation with the '+' operator.
  1174.     All string-types are compatible, so you may catenate any chars,
  1175.     fixed length strings and variable length strings with each other.
  1176.  
  1177. program scat (input, output);
  1178.  
  1179. var
  1180.    ch           : char;
  1181.    str           : string(100);
  1182.    str2           : string(50);
  1183.    fstr        : packed array [ 1 .. 20 ] of char;
  1184.  
  1185. begin
  1186.    ch   := '$';
  1187.    fstr := 'demo'; { padded with blanks }
  1188.    write ('Give me some chars to play with: ');
  1189.    readln (str);
  1190.    str := '^' + 'prefix:' + str + ':suffix:' + fstr + ch;
  1191.    writeln ('Len' + 'gth = ', length (str));
  1192.    writeln (str);
  1193. end.
  1194.  
  1195.  
  1196. TYPE QUALIFIERS:
  1197. ----------------
  1198.  
  1199.     @@ New feature.
  1200.     @@ Currently gpc runtime does not know anything about these.
  1201.     @@ These may change/or get removed...
  1202.  
  1203.     As an extension, GPC allows you to use type qualifiers:
  1204.     
  1205.     __byte__        : 8 bit integer
  1206.     __short__        : Short integer (16 bits) or real type (32 bits)
  1207.     __long__        : Long integer or real type
  1208.     __longlong__        : long long integer type (64 bits)
  1209.     __unsigned__        : Unsigned INTEGER type
  1210.  
  1211.     The __unsigned__ works for all integer types, also those
  1212.     that have been previously declared with some other type
  1213.     qualifier, like __short__. The other qualifiers do not accept
  1214.     types that have already been modified with a type qualifier.
  1215.  
  1216.     The syntax to use the qualifiers:
  1217.  
  1218.         type-denoter > TYPE-QUALIFIER type-name
  1219.  
  1220.     (The metasymbol > means type-denoter has also other meanings)
  1221.  
  1222.     Most of these should be done with subranges anyway.
  1223.     However, '__short__ real' can not be done like that, neither can
  1224.     '__unsigned__ integer' or '__longlong__ integer'.
  1225.  
  1226.  
  1227. program zap(output);
  1228.  
  1229. type
  1230.    byte        = __byte__     integer;
  1231.    longint  = __long__     integer;
  1232.    float    = __short__    real;
  1233.    u_long   = __unsigned__ longint;
  1234.    verylong = __longlong__ integer;
  1235.  
  1236. var
  1237.   i8  : byte;
  1238.   i16 : __short__ integer;
  1239.   foo : u_long;
  1240.   pi  : float;
  1241.   big : verylong;
  1242.  
  1243. begin
  1244.   pi  := 3.141592654;
  1245.   i16 := 1000;
  1246.   big := MaxInt * i16;
  1247.   i8  := 127;
  1248.     
  1249.   (*
  1250.    * Hmm, does not work because constant is treated as an integer,
  1251.    * and this is too large. Need a method to specify long constants.
  1252.    *
  1253.    * What is the syntax in other Pascal compilers? Suggestions, please!
  1254.    *    
  1255.     
  1256.   foo := 16#deadbeef;
  1257.     
  1258.    *)
  1259. end.
  1260.     
  1261.  
  1262. ACCESSING COMMAND LINE ARGUMENTS:
  1263. ---------------------------------
  1264.  
  1265.     The following module accesses the command line with
  1266.     ParamStr and ParamCount functions.
  1267.  
  1268.     These follow the Un*x semantics, so that 
  1269.     arg[0] == program name,
  1270.     arg[1] .. arg[ParamCount-1] are the arguments.
  1271.  
  1272. MODULE command_line interface;
  1273.  
  1274. EXPORT cmdline = (Max_length, Arg_type, ParamStr, ParamCount);
  1275.  
  1276. CONST
  1277.    Max_length =     255; { Max length of each argument.
  1278.             If some arg is longer, the run time system
  1279.             traps it.
  1280.               }
  1281.  
  1282. TYPE
  1283.    Arg_type = String(Max_length);
  1284.  
  1285.   FUNCTION ParamCount: Integer;
  1286.  
  1287.   FUNCTION ParamStr (arg_num: integer): Arg_type;
  1288. END. { command_line interface }
  1289.  
  1290. MODULE command_line implementation;
  1291.  
  1292.   { These are in the GPC runtime library }
  1293.   FUNCTION _p_paramcount : Integer; C;
  1294.   FUNCTION _p_paramstr (num: Integer; VAR str: String): Boolean; C;
  1295.  
  1296.   FUNCTION ParamCount;
  1297.   BEGIN
  1298.      ParamCount := _p_paramcount;
  1299.   END; { ParamCount }
  1300.  
  1301.   FUNCTION ParamStr;
  1302.   
  1303.   VAR
  1304.    Str           : Arg_type;
  1305.    Success     : Boolean;
  1306.  
  1307.   BEGIN
  1308.      Success := _p_paramstr (arg_num, Str);
  1309.  
  1310.      (* Should perhaps do something else on failure.
  1311.       *
  1312.       * Now it returns the empty string, which is also a valid
  1313.       * parameter.
  1314.       *)
  1315.      IF Success THEN
  1316.     ParamStr := Str
  1317.      else
  1318.     ParamStr := '';
  1319.   END; { ParamStr }
  1320. END. { command_line implementation }
  1321.  
  1322.  
  1323. { The program below, when compiled with the interface module and
  1324.   linked with the implementation module, accesses the command
  1325.   line arguments.
  1326. }    
  1327.  
  1328. program zap (output);
  1329.  
  1330. import cmdline;
  1331.  
  1332. var
  1333.    counter : integer;
  1334.  
  1335. begin
  1336.    writeln ('Program fetches command line arguments and outputs one per line');
  1337.    writeln ('Max length of each argument is ',Max_Length:1,' characters');
  1338.  
  1339.    for counter := 0 to ParamCount-1 do
  1340.       writeln ('Command line arg ',counter:1,' is "',paramstr(counter),'"');
  1341. end.
  1342.  
  1343.  
  1344. RUN TIME SYSTEM FLAGS:
  1345. ----------------------
  1346.  
  1347.     There are some flags for the run time system, and now that
  1348.     the pascal programs are able to access the command line, the
  1349.     rts flag passing works as described.
  1350.  
  1351.     The run time system command line args are invisible to the user
  1352.     program, unless '-s' rts flag is given.
  1353.  
  1354.     If you want to give flags to the run time system, the
  1355.     FIRST argument has to be (literally):
  1356.  
  1357.     -Grts
  1358.  
  1359.     After this, the run time system recognizes the following args
  1360.     in any order, up to the first arg it does not know.
  1361.  
  1362.     -h         : give help of rts flags and exit(1).
  1363.     -d         : set internal debugging (incremental)
  1364.     -w         : give warnings (I don't know if this is useful)
  1365.     -s         : pass also rts flags to user program
  1366.     -i ARG         : Pass ARG as one line to the program standard input
  1367.     -a pfile:extname : Associate pascal external file Pfile to file extname
  1368.     --         : Rest of the args are not for the run time system
  1369.  
  1370.     You may give multiple -a options for the same Pfile. They are accessed
  1371.     in order with e.g. "close(pfile); reset(pfile);"
  1372.  
  1373.     Also Input and Output may be bound with -a.
  1374.  
  1375.     If the files bound with -a rts option does not contain the file
  1376.     being opened, the run time system asks the file name from the
  1377.     users terminal. If that is not available, read input from
  1378.     standard input. If that is not available, exit with an error message.
  1379.  
  1380.     You may give multiple '-i ARG' options to stack lines to the 'standard
  1381.     input'. When they run out, the program starts reading the real
  1382.     standard input, if available. (@@@ Does not yet work well :-)
  1383.     
  1384.  
  1385. HOW TO SEND A BUG REPORT:
  1386. -------------------------
  1387.  
  1388.     - Indicate the GCC version, GPC version and the configuration
  1389.       of GCC (what was given to GCC configure script; see file
  1390.       config.status in the GCC compilation directory)
  1391.  
  1392.     - Give an abstract (a few lines) of the nature of the
  1393.       problem.
  1394.  
  1395.     - State only facts in you bug reports.
  1396.  
  1397.     - Try to generate the SHORTEST POSSIBLE sample code that still
  1398.       invokes the bug. If this is not possible, send the bug report
  1399.       anyway. Remember: If you do more work here, others may be able
  1400.       to find out and fix the problem sooner so you can continue
  1401.       your work faster.
  1402.     
  1403.     - Send the info above and all other info you think is useful
  1404.       either to me or the list of gpc testers.
  1405.  
  1406.        My email address: jtv@hut.fi
  1407.        GPC testers list: gpc@hut.fi
  1408.     
  1409.  
  1410. IMPLEMENTATION DEFINED FEATURES:
  1411. --------------------------------
  1412.  
  1413.     The following corresponds to the ISO/IEC 10206 : 1991 standard
  1414.     of the programming language Extended Pascal, Annex E, page 186:
  1415.  
  1416.     E.1  String type may contain any character that is legal in
  1417.          CHAR type and vice versa??? See E.9.
  1418.  
  1419.     E.2  Alternate reference token "@" is supported.       vs  "^"
  1420.          Alternate comment delimiters "{ }" are supported. vs: "(* *)"
  1421.          Alternate subscripts "(. .)" are supported.       vs: "[ ]"
  1422.         
  1423.     E.3  The value of Maxint varies per target machine. It is
  1424.          the maximum value that fits in the target machines
  1425.          integer type, usually 32 bits.
  1426.  
  1427.     E.4  Real-type accuracy and range varies per target machine.
  1428.          Double precision is currently used to represent real-type.
  1429.  
  1430.     E.5  Value of Minreal varies per target machine.
  1431.  
  1432.     E.6  Value of Maxreal varies per target machine.
  1433.  
  1434.     E.7  Value of Epsreal varies per target machine.
  1435.  
  1436.     E.8  The accuracy of real arithmetic operation varies per
  1437.          target machine.
  1438.  
  1439.     E.9  Eight bit ascii codes are used to represent Char type.
  1440.          (@@@@ C-style \-character escapes are supported)
  1441.  
  1442.     E.10 Eight bit ascii codes are used to represent Char type.
  1443.  
  1444.     E.11 Value of Maxchar is 255
  1445.          (@@@@ Is it really????? On some machines it seems to be 127)
  1446.  
  1447.     E.12 The values of complex type are represented by two real
  1448.          values. See E.4.
  1449.  
  1450.     E.13 The accuracy of complex arithmetic varies per target machine.
  1451.  
  1452.     E.14 The Capacity of the variable length string type in the
  1453.          NAME field of the BindingType record is: 255 characters.
  1454.  
  1455.     E.15 The only external entities supported are of FILE type.
  1456.          The run time system may cache the file modifications until
  1457.          the file is closed. The binding of a name to a file type
  1458.          object has no effect on the file until it is opened, in which
  1459.          case the bound name is used to access the external file.         
  1460.          
  1461.     E.16 The binding procedure BIND(F,B) associates the object F with
  1462.          the NAME field of the BindingType parameter B.
  1463.          
  1464.          Currently GPC allows binding of FILE TYPE objects only.
  1465.          When the binding is applied to a file type object, the
  1466.          file must not be opened by the Pascal program.
  1467.  
  1468.          (@@@ Should a file be closed if it is open when bound?).
  1469.  
  1470.          When a bound file is opened with reset,rewrite or extend,
  1471.          the file name bound to the pascal file is used to name the
  1472.          target file in the system. This method has precedence over
  1473.          all other file naming methods (See. E.34)
  1474.  
  1475.          If the required procedure UNBIND(F) is applied to a file
  1476.          type object, the file is first CLOSED if it is open. Then
  1477.          all the bindings existing with the object F are removed.
  1478.          
  1479.          After UNBIND(F), the BIND may be applied to object F again. 
  1480.  
  1481.     E.17 The systems notion of the current local date.
  1482.  
  1483.     E.18 The systems notion of the current local wall clock time.
  1484.  
  1485.     E.19 Function `binding(F)' returns the binding state of an object
  1486.          F. If it has been previously bound to an external entity,
  1487.          the returned BindingType record will contain TRUE in the
  1488.          required field BOUND, otherwise it is FALSE.
  1489.  
  1490.          If the BOUND field is true, then the NAME field contains the
  1491.          string where it is bound to.
  1492.  
  1493.          The required record type BindinType is extended with the
  1494.          fields marked with `@'-character in the comment below:
  1495.  
  1496.         BindingType = PACKED RECORD
  1497.           Bound        : Boolean;     (* required field BOUND   *)
  1498.           Extensions_Valid  : Boolean;     (* @ Extended fields valid? *)
  1499.           Writable          : Boolean;     (* @ File is WRITABLE *)
  1500.           Readable          : Boolean;     (* @ File is READABLE *)
  1501.           Existing          : Boolean;     (* @ File EXISTS      *)
  1502.           Error             : Integer;     (* @ UNUSED currently *)
  1503.           Size              : Integer;     (* @ # of elements or -1 *)
  1504.           Name        : String(255); (* required field NAME *)
  1505.         END;
  1506.  
  1507.          If the BOUND field is FALSE, the required field NAME does not
  1508.          contain valid data. All the extended Boolean type fields are
  1509.          initialized to FALSE.
  1510.  
  1511.          Unbind: See E.16.
  1512.  
  1513.     E.20 The length of the string returned by date(t) is 11 characters.
  1514.  
  1515.     E.21 The three fields returned by date(t) are separated by a space,
  1516.          and they are to be interpreted as follows:
  1517.           1) two characters as specified by t.day.
  1518.          If t.day < 10 the first character is space otherwise
  1519.          it is a digit.
  1520.           2) three characters from the beginning of the english
  1521.          name of the month as specified by t.month, first letter
  1522.          capitalized, the other two in lower case.
  1523.           3) The year from t.year
  1524.  
  1525.           Example:  '15 Nov 1993'
  1526.  
  1527.     E.22 The length of the string returned by time(t) is 8 characters.
  1528.  
  1529.     E.23 The three fields returned by time(t) are separated by a colon.
  1530.          Each field consists of exactly two digits and they are to be
  1531.          interpreted as follows:
  1532.           1) The hour   from t.hour
  1533.           2) The minute from t.minute
  1534.           3) The second from t.second
  1535.  
  1536.           Example:  '23:45:05'
  1537.  
  1538.     E.24 TotalWidth for integer type is 10
  1539.  
  1540.     E.25 TotalWidth for real type is 14
  1541.  
  1542.     E.26 TotalWidth for boolean type is 6
  1543.  
  1544.     E.27 ExpDigits varies by the size of the exponent
  1545.          from 2 digits upward. Max size is target dependent.
  1546.  
  1547.     E.28 The exponent character 'e' is used in output.
  1548.          'E' is also recognized in input.
  1549.  
  1550.     E.29 The case of boolean values output is: "  True" and " False"
  1551.  
  1552.     E.30 page(f) outputs the character FORM-FEED (octal 014)
  1553.  
  1554.     E.31 @ The module parameters are currently not bound
  1555.          to external entities. Instead, they are ignored.
  1556.          (@@@ Check this)
  1557.  
  1558.     E.32 The effect of reset, rewrite and extend to textfile INPUT:
  1559.            reset)    @@@@ Verify this.
  1560.            rewrite)  @@@@ Verify this.
  1561.            extend)   @@@@ Verify this.
  1562.  
  1563.     E.33 The effect of reset, rewrite and extend to textfile OUTPUT:
  1564.          @@@@ Vefify these.
  1565.     
  1566.     E.34 External entities (files) are associates to their external
  1567.          representation currently (in order) with:
  1568.           1) binding the object with bind() procedure.
  1569.           2) Non-standard extra parameter for rewrite/reset/extend
  1570.           3) -a Internalname:external-file-name command line switch
  1571.          (See run time system flags)
  1572.           4) the binding is requested from terminal by the run
  1573.           time system.
  1574.  
  1575.  
  1576. IMPLEMENTATION DEPENDENT FEATURES:
  1577. ----------------------------------
  1578.  
  1579.     The following corresponds to the ISO/IEC 10206 : 1991 standard
  1580.     of the programming language Extended Pascal, Annex F, page 189:
  1581.  
  1582.     @@@ *** Add info here ***
  1583.  
  1584.     F.1
  1585.     F.2
  1586.     F.3
  1587.     F.4
  1588.     F.5
  1589.     F.6
  1590.     F.7
  1591.     F.8
  1592.     F.10
  1593.     F.11
  1594.     F.12
  1595.     F.13
  1596.     F.14
  1597.     F.15
  1598.     F.16
  1599.     F.17
  1600.     F.18
  1601.     
  1602.  
  1603. RESULTS OF SOME IMPLEMENTATION DEPENDENT TEST PROGRAMS:
  1604. -------------------------------------------------------
  1605.  
  1606.     The programs were run in i486 with Mach 3/CMU UX (BSD) system.
  1607.     Here are the results of the implementation dependent test:
  1608.  
  1609. ======= p641
  1610. ### p641 -->  IMPLEMENTATION DEFINED...6.1.7-15
  1611. ======= p642
  1612. ### p642 -->  OUTPUT FROM TEST...6.1.9-5
  1613.  ALTERNATE SUBSCRIPT BRACKETS IMPLEMENTED
  1614.  ALTERNATE COMMENT DELIMITERS IMPLEMENTED
  1615.  IMPLEMENTATION DEFINED...6.1.9-5
  1616. ======= p643
  1617. ### p643 -->  OUTPUT FROM TEST...6.4.2.2-10
  1618.  THE VALUE OF MAXINT IS 2147483647
  1619.  IMPLEMENTATION DEFINED...6.4.2.2-10
  1620. ======= p644
  1621. ### p644 -->  OUTPUT FROM TEST...6.4.2.2-11
  1622.  ACCURACY OF UNSIGNED-REAL IS
  1623.  16 DECIMAL PLACES
  1624.  IMPLEMENTATION DEFINED...6.4.2.2-11
  1625. ======= p645
  1626. ### p645 -->  OUTPUT FROM TEST...6.4.2.2-12
  1627.  ORDINAL VALUES OF CHARACTERS
  1628.  VALUE    CHAR BETWEEN DECIMAL POINTS
  1629.    65        .A. UPPER CASE LETTER
  1630.    66        .B. UPPER CASE LETTER
  1631.    67        .C. UPPER CASE LETTER
  1632.    68        .D. UPPER CASE LETTER
  1633.    69        .E. UPPER CASE LETTER
  1634.    70        .F. UPPER CASE LETTER
  1635.    71        .G. UPPER CASE LETTER
  1636.    72        .H. UPPER CASE LETTER
  1637.    73        .I. UPPER CASE LETTER
  1638.    74        .J. UPPER CASE LETTER
  1639.    75        .K. UPPER CASE LETTER
  1640.    76        .L. UPPER CASE LETTER
  1641.    77        .M. UPPER CASE LETTER
  1642.    78        .N. UPPER CASE LETTER
  1643.    79        .O. UPPER CASE LETTER
  1644.    80        .P. UPPER CASE LETTER
  1645.    81        .Q. UPPER CASE LETTER
  1646.    82        .R. UPPER CASE LETTER
  1647.    83        .S. UPPER CASE LETTER
  1648.    84        .T. UPPER CASE LETTER
  1649.    85        .U. UPPER CASE LETTER
  1650.    86        .V. UPPER CASE LETTER
  1651.    87        .W. UPPER CASE LETTER
  1652.    88        .X. UPPER CASE LETTER
  1653.    89        .Y. UPPER CASE LETTER
  1654.    90        .Z. UPPER CASE LETTER
  1655.    48        .0. DIGIT
  1656.    49        .1. DIGIT
  1657.    50        .2. DIGIT
  1658.    51        .3. DIGIT
  1659.    52        .4. DIGIT
  1660.    53        .5. DIGIT
  1661.    54        .6. DIGIT
  1662.    55        .7. DIGIT
  1663.    56        .8. DIGIT
  1664.    57        .9. DIGIT
  1665.    43        .+. PLUS
  1666.    45        .-. MINUS
  1667.    42        .*. MULTIPLY
  1668.    47        ./. DIVIDE
  1669.    61        .=. EQUALS
  1670.    60        .<. LESS THAN
  1671.    62        .>. GREATER THAN
  1672.    46        ... DECIMAL POINT
  1673.    44        .,. COMMA
  1674.    58        .:. COLON
  1675.    59        .;. SEMICOLON
  1676.    94        .^. UP-ARROW OR COMMERCIAL AT
  1677.    40        .(. OPEN ROUND BRACKET
  1678.    41        .). CLOSED ROUND BRACKET
  1679.    32        . . SPACE
  1680.    39        .'. APOSTROPHE
  1681.    97        .a. LOWER CASE LETTER
  1682.    98        .b. LOWER CASE LETTER
  1683.    99        .c. LOWER CASE LETTER
  1684.   100        .d. LOWER CASE LETTER
  1685.   101        .e. LOWER CASE LETTER
  1686.   102        .f. LOWER CASE LETTER
  1687.   103        .g. LOWER CASE LETTER
  1688.   104        .h. LOWER CASE LETTER
  1689.   105        .i. LOWER CASE LETTER
  1690.   106        .j. LOWER CASE LETTER
  1691.   107        .k. LOWER CASE LETTER
  1692.   108        .l. LOWER CASE LETTER
  1693.   109        .m. LOWER CASE LETTER
  1694.   110        .n. LOWER CASE LETTER
  1695.   111        .o. LOWER CASE LETTER
  1696.   112        .p. LOWER CASE LETTER
  1697.   113        .q. LOWER CASE LETTER
  1698.   114        .r. LOWER CASE LETTER
  1699.   115        .s. LOWER CASE LETTER
  1700.   116        .t. LOWER CASE LETTER
  1701.   117        .u. LOWER CASE LETTER
  1702.   118        .v. LOWER CASE LETTER
  1703.   119        .w. LOWER CASE LETTER
  1704.   120        .x. LOWER CASE LETTER
  1705.   121        .y. LOWER CASE LETTER
  1706.   122        .z. LOWER CASE LETTER
  1707.  IMPLEMENTATION DEFINED...6.4.2.2-12
  1708. ======= p646
  1709. ### p646 -->  OUTPUT FROM TEST...6.6.6.2-11
  1710.    BETA =    2
  1711.       T =   53
  1712.     RND =    1
  1713.    NGRD =    0
  1714.  MACHEP =  -52
  1715.   NEGEP =  -53
  1716.    IEXP =   11
  1717.  MINEXP =-1022
  1718.  MAXEXP = 1022
  1719.     EPS = 2.2204460e-16
  1720.  EPSNEG = 1.1102230e-16
  1721.    XMIN = 2.2250739e-308
  1722.    XMAX = 4.4942328e+307
  1723.  IMPLEMENTATION DEFINED...6.6.6.2-11
  1724. ======= p647
  1725. ### p647 -->  OUTPUT FROM TEST...6.7.2.2-17
  1726.  ACCURACY OF REAL OPERATIONS IS
  1727.  ABOUT 16 DECIMAL PLACES
  1728.  IMPLEMENTATION DEFINED...6.7.2.2-17
  1729. ======= p648
  1730. ### p648 -->  OUTPUT FROM TEST...6.9.3.1-1
  1731.  DEFAULT OUTPUT WIDTH FOR REALS
  1732.  TOTALWIDTH DEFAULT VALUE =   14 CHARACTERS
  1733.  IMPLEMENTATION DEFINED...6.9.3.1-1
  1734. ======= p649
  1735. ### p649 -->  OUTPUT FROM TEST...6.9.3.1-8
  1736.  DEFAULT OUTPUT WIDTH FOR BOOLEANS
  1737.  TOTALWIDTH DEFAULT VALUE =    6 CHARACTERS
  1738.  IMPLEMENTATION DEFINED...6.9.3.1-8
  1739. ======= p650
  1740. ### p650 -->  OUTPUT FROM TEST...6.9.3.1-9
  1741.  DEFAULT OUTPUT WIDTH FOR INTEGERS
  1742.  TOTALWIDTH DEFAULT VALUE =   10 CHARACTERS
  1743.  IMPLEMENTATION DEFINED...6.9.3.1-9
  1744. ======= p651
  1745. ### p651 -->  OUTPUT FROM TEST...6.9.3.4.1-1
  1746.  NUMBER OF DIGITS IN AN EXPONENT
  1747.  EXPDIGITS IS    2
  1748.  IMPLEMENTATION DEFINED...6.9.3.4.1-1
  1749. ======= p652
  1750. ### p652 -->  OUTPUT FROM TEST...6.9.3.4.1-2
  1751.  IMPLEMENTATION DEFINED EXPONENT CHARACTER
  1752.  IS e
  1753.  LOWER CASE
  1754.  IMPLEMENTATION DEFINED...6.9.3.4.1-2
  1755. ======= p653
  1756. ### p653 -->  OUTPUT FROM TEST...6.9.3.5-1
  1757.  CASE OF BOOLEAN VALUES
  1758.  TRUE, FALSE
  1759.  ULLL, ULLLL
  1760.  IMPLEMENTATION DEFINED...6.9.3.5-1
  1761. ======= p654
  1762. ### p654 -->  OUTPUT FROM TEST...6.5.3.2-6
  1763.  EVALUATION ORDER OF V(.A,B,C.) IS ABC
  1764.  IMPLEMENTATION DEPENDENT...6.5.3.2-6
  1765. ======= p655
  1766. ### p655 -->  OUTPUT FROM TEST...6.6.5.2-16
  1767.  NUMBER OF EVALUATIONS OF F IN READ(F,A,B,C) IS  1
  1768.  IMPLEMENTATION DEPENDENT...6.6.5.2-16
  1769. ======= p656
  1770. ### p656 -->  OUTPUT FROM TEST...6.6.5.2-17
  1771.  NUMBER OF EVALUATIONS OF F IN WRITE(F,A,B,C) IS  1
  1772.  IMPLEMENTATION DEPENDENT...6.6.5.2-17
  1773. ======= p657
  1774. ### p657 -->  OUTPUT FROM TEST...6.6.5.4-8
  1775.  ORDER OF EVALUATION OF PACK(A,I,Z) IS AIZ    
  1776.  IMPLEMENTATION DEPENDENT...6.6.5.4-8
  1777. ======= p658
  1778. ### p658 -->  OUTPUT FROM TEST...6.6.5.4-9
  1779.  ORDER OF EVALUATION OF UNPACK(Z,A,I) IS AIZ    
  1780.  IMPLEMENTATION DEPENDENT...6.6.5.4-9
  1781. ======= p659
  1782. ### p659 -->  OUTPUT FROM TEST...6.7.1-11
  1783.  ORDER OF EVALUATION OF (. A, B, C .) IS ABC
  1784.  IMPLEMENTATION DEPENDENT...6.7.1-11
  1785. ======= p660
  1786. ### p660 -->  OUTPUT FROM TEST...6.7.1-12
  1787.  ORDER OF EVALUATION OF (. A..B .) IS AB
  1788.  IMPLEMENTATION DEPENDENT...6.7.1-12
  1789. ======= p661
  1790. ### p661 -->  IMPLEMENTATION DEPENDENT...6.7.1-13
  1791. ======= p662
  1792. ### p662 -->  OUTPUT FROM TEST...6.7.1-14
  1793.  ORDER OF EVALUATION OF (. A .. B .) IS AB
  1794.  IMPLEMENTATION DEPENDENT...6.7.1-14
  1795. ======= p663
  1796. ### p663 -->  OUTPUT FROM TEST...6.7.2.3-3
  1797.  TEST OF SHORT CIRCUIT EVALUATION OF (A AND B)
  1798.  BOTH EXPRESSIONS EVALUATED
  1799.  IMPLEMENTATION DEPENDENT...6.7.2.3-3
  1800. ======= p664
  1801. ### p664 -->  OUTPUT FROM TEST...6.7.2.3-4
  1802.  TEST OF SHORT CIRCUIT EVALUATION OF (A OR B)
  1803.  BOTH EXPRESSIONS EVALUATED
  1804.  IMPLEMENTATION DEPENDENT...6.7.2.3-4
  1805. ======= p665
  1806. ### p665 -->  OUTPUT FROM TEST...6.7.3-2
  1807.  ORDER OF EVALUATION OF F(F(A,B),F(C,D)) IS DCBA
  1808.  IMPLEMENTATION DEPENDENT...6.7.3-2
  1809. ======= p666
  1810. ### p666 -->  OUTPUT FROM TEST...6.8.2.2-1
  1811.  TEST OF BINDING ORDER (A[I] := EXPRESSION)
  1812.  EVALUATION THEN SELECTION
  1813.  IMPLEMENTATION DEPENDENT...6.8.2.2-1
  1814. ======= p667
  1815. ### p667 -->  OUTPUT FROM TEST...6.8.2.2-2
  1816.  TEST OF BINDING ORDER (P^ := EXPRESSION)
  1817.  EVALUATION THEN SELECTION
  1818.  IMPLEMENTATION DEPENDENT...6.8.2.2-2
  1819. ======= p668
  1820. ### p668 -->  OUTPUT FROM TEST...6.8.2.3-2
  1821.  ACTUAL PARAMETERS EVALUATED IN REVERSE ORDER
  1822.  IMPLEMENTATION DEPENDENT...6.8.2.3-2
  1823. ======= p669
  1824. ### p669 -->  OUTPUT FROM TEST...6.9.5-3
  1825.  SEQUENCE CORRESPONDING TO PAGE
  1826.  CHAR, ORD(C)=         12
  1827.  IMPLEMENTATION DEPENDENT...6.9.5-3
  1828. ======= p727
  1829. ### p727 -->  OUTPUT FROM TEST...6.1.9-6
  1830.  EQUIVALENT SYMBOL TO UP-ARROW IS IMPLEMENTED
  1831.  IMPLEMENTATION DEFINED...6.1.9-6
  1832.